/*
 * Copyright (C) 2020, 2019, 2018, 2017 Girish M
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 */

/*
Problem statement: https://www.isical.ac.in/~pdslab/2017/exams/labtest1.pdf
*/

 #include "common.h"

char isPermutation(char* str1, char* str2)
{
  int i = 0, j = 0;
  char alpha = 'a';
  static int charFreq1[26], charFreq2[26];
  if(strlen(str1) == strlen(str2))
  {
     while((*(str1+i) != '\0') && (*(str2+i) != '\0'))
     {
       charFreq1[*(str1+i)-alpha]++;
       charFreq2[*(str2+i)-alpha]++;
       i++;
     }
     for(j=0; j<strlen(str1); j++)
     {
       if(charFreq1[j] != charFreq2[j])
       {
         return 0;
       }
     }
     return 1;
  }
  else
     return 0;
}

int main(int argc, char* argv[])
{
  if(argc == 3)
  {
    if(isPermutation(argv[1], argv[2]))
      printf("YES\n");
    else
      printf("NO\n");
  }
  else
      printf("\nUsage: ./cs1713-test1-prog2.o str1 str2\n");
  return 0;
}
